#include "./../inc/draw.h"

int toolbar_init()
{
    int *pen = getBMP_IMG("./res/pen.bmp", 40, 40);
    int *eraser = getBMP_IMG("./res/eraser.bmp", 40, 40);
    int *R = getBMP_IMG("./res/return.bmp", 40, 40);
    for (int row = 0; row < 48; row++)
    {
        for (int col = 0; col < 800; col++)
        {

            if (row >= 5 && row < 45 && col >= 5 && col < 55)
            {
                if (row >= 5 && row < 45 && col >= 5 && col < 45)
                {
                    int img_row = row - 5;
                    int img_col = col - 5;
                    lcd_mmap[row][col] = pen[img_row * 40 + img_col];
                }
            }
            // 半径为5的圆
            else if (row >= 5 && row < 45 && col >= 55 && col < 95)
            {
                int center_x = 55 + 20; // 圆心x坐标
                int center_y = 5 + 20;  // 圆心y坐标
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 5 * 5)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为10的圆
            else if (row >= 5 && row < 45 && col >= 105 && col < 145)
            {
                int center_x = 105 + 20; // 圆心x坐标
                int center_y = 5 + 20;   // 圆心y坐标
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 10 * 10)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为15的圆
            else if (row >= 5 && row < 45 && col >= 155 && col < 195)
            {
                int center_x = 155 + 20; // 圆心x坐标
                int center_y = 5 + 20;   // 圆心y坐标
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 15 * 15)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为20的圆
            else if (row >= 5 && row < 45 && col >= 205 && col < 245)
            {
                int center_x = 205 + 20; // 圆心x坐标
                int center_y = 5 + 20;   // 圆心y坐标
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 20 * 20)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 黄色正方形
            else if (row >= 10 && row < 40 && col >= 255 && col < 305)
            {
                if (col >= 260 && col < 290)
                {
                    lcd_mmap[row][col] = YELLOW;
                }
            }
            // 红色正方形
            else if (row >= 10 && row < 40 && col >= 305 && col < 355)
            {
                // 在50宽度容器中居中绘制30x30正方形
                if (col >= 310 && col < 340) // 305 + 5 = 310, 310 + 30 = 340
                {
                    lcd_mmap[row][col] = RED;
                }
            }
            // 绿色正方形
            else if (row >= 10 && row < 40 && col >= 355 && col < 405)
            {
                // 在50宽度容器中居中绘制30x30正方形
                if (col >= 360 && col < 390) // 355 + 5 = 360, 360 + 30 = 390
                {
                    lcd_mmap[row][col] = GREEN;
                }
            }
            // 蓝色正方形
            else if (row >= 10 && row < 40 && col >= 405 && col < 455)
            {
                if (col >= 410 && col < 440) // 405 + 5 = 410, 410 + 30 = 440
                {
                    lcd_mmap[row][col] = BLUE;
                }
            }
            else if (row >= 5 && row < 45 && col >= 455 && col < 505)
            {
                if (col >= 460 && col < 500)
                {
                    int img_row = row - 5;
                    int img_col = col - 460;
                    lcd_mmap[row][col] = eraser[img_row * 40 + img_col];
                }
            }
            // 半径为5的圆
            else if (row >= 5 && row < 45 && col >= 505 && col < 555)
            {
                int center_x = 505 + 20; // 圆心x坐标：505 + 50/2 = 530
                int center_y = 5 + 20;   // 圆心y坐标：5 + 40/2 = 25
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 5 * 5)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为10的圆
            else if (row >= 5 && row < 45 && col >= 555 && col < 605)
            {
                int center_x = 555 + 20; // 圆心x坐标：555 + 50/2 = 580
                int center_y = 5 + 20;   // 圆心y坐标：5 + 40/2 = 25
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 10 * 10)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为15的圆
            else if (row >= 5 && row < 45 && col >= 605 && col < 655)
            {
                int center_x = 605 + 20; // 圆心x坐标：605 + 50/2 = 630
                int center_y = 5 + 20;   // 圆心y坐标：5 + 40/2 = 25
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 15 * 15)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为20的圆
            else if (row >= 5 && row < 45 && col >= 655 && col < 705)
            {
                int center_x = 655 + 20; // 圆心x坐标：655 + 50/2 = 680
                int center_y = 5 + 20;   // 圆心y坐标：5 + 40/2 = 25
                int dx = col - center_x;
                int dy = row - center_y;
                if (dx * dx + dy * dy <= 20 * 20)
                {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            else if (row >= 5 && row < 45 && col >= 750 && col < 800)
            {
                if (col >= 755 && col < 795)
                {
                    int img_row = row - 5;
                    int img_col = col - 755;
                    lcd_mmap[row][col] = R[img_row * 40 + img_col];
                }
            }
            else
            {
                lcd_mmap[row][col] = WHITE;
            }
        }
    }
    free(R);
    free(pen);
    free(eraser);
    return 0;
}